import { createRenderer } from '@vue/runtime-core'

import {Text,Container,Sprite ,Texture} from 'pixi.js'
const renderer = createRenderer({
    createElement(type) {
        let element
       switch (type){
           case 'Container':
               element = new Container()
               break;
           case 'Sprite':
               element = new Sprite()
               break;
       }
        //绘制矩形
/*        let element;
        if (type === 'react'){
            element = new Graphics();
            element.beginFill(0xfff);
            element.drawRect(0,0,500,500);
            element.endFill();
        }else if (type === 'circle'){
            element = new Graphics();
            element.beginFill(0xff000);
            element.drawCircle(0,0,50);
            element.endFill();
        }*/
        return element;
    },
    patchProp(el, key, prevValue, nextValue) { //对应小矩形位置
        //pixi
        //el.x=value
        //el.y=value
        //el[key] = nextValue
        switch (key){
            case 'texture':
                el.texture = Texture.from(nextValue)
                break;
            case 'onClick1':
                el.on("pointertap",nextValue)
                break;
            default:
                el[key] = nextValue
        }
    },
    setElementText(node, text) {//对应我的头发的文本
        const cText = new Text(text);
        node.addChild(cText)
    },
    createText(text) { //circle 的 text
        return new Text(text)
    },
    insert(el, parent) {
        //console.log(el,parent)
        parent.addChild(el)
    },
    //新增
    //处理注释
    createComment(text) {
        //console.log(text);
    },
    //获取父节点
    parentNode(node) {
        //console.log(node);
    },
    nextSibling(node) {
       // console.log(node);
    },
    remove(el) {
        const parent = el.parent
        if (parent){
            parent.removeChild(el)
        }
    }

});

export function createApp(rooterComponent){
    return renderer.createApp(rooterComponent)
}